package com.demo.web_06;

import javax.servlet.annotation.WebServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

    @WebServlet("/register_do")
public class RegisterServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().append("Hello Servlet");
        System.out.println("111");
        HttpSession session = req.getSession();
        if (session != null) {
            session.invalidate(); // 手动销毁 Session
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 得到请求的URL地址
        String requestUrl = req.getRequestURL().toString();
        // 设置将字符以"UTF-8"编码输出到客户端浏览器
        resp.setCharacterEncoding("UTF-8");
        // 通过设置响应头控制浏览器以UTF-8的编码显示数据
//        resp.setHeader("content-type", "text/html;charset=UTF-8");
        //        拿到的是web.xml文件的参数
        //    <context-param>
        //        <param-name>appVersion</param-name>
        //        <param-value>1.0</param-value>
        //    </context-param>
        String servletName = getServletConfig().getServletContext().getInitParameter("appVersion");
        String name = getServletContext().getInitParameter("appVersion");
        System.out.println(servletName);
        System.out.println(name);
    }
}